-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tcgc] new spread behavior #886
Conversation
All changed packages have been documented.
Show changes
|
You can try these changes at https://cadlplayground.z22.web.core.windows.net/typespec-azure/prs/886/ Check the website changes at https://tspwebsitepr.z22.web.core.windows.net/typespec-azure/prs/886/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @tadelesh
Could we add some guidance on how should emitter adopt this? |
added in description. |
Overall looks good to me. Just to confirm: so emitter will use body param's |
Tested on Java emitter, should be good now. |
@@ -64,7 +64,6 @@ import { | |||
getCrossLanguageDefinitionId, | |||
getCrossLanguagePackageId, | |||
getDefaultApiVersion, | |||
getEffectivePayloadType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deco getEffectivePayloadType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think java won't use this. So, agree on deprecation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is still used in response.
deepStrictEqual(op.bodyParam.correspondingMethodParams, [documentMethodParam]); | ||
}); | ||
|
||
it("anonymous model with @body should not be spread", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a case for alias? I believe it is the same as spread model?
alias Test = {
prop: string
};
op test(...Test): void;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this one? Also spread case, right?
model Test {
@header
foo: string;
prop: string
};
op test(...Test): void;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as spread model, i think it has been covered by another case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I take is
- if there is
@body
or@bodyRoot
anywhere, it is explicit body, and it is not spread - otherwise, it is implicit body, and it is spread
model or alias no longer matter.
@@ -598,4 +598,6 @@ export enum UsageFlags { | |||
JsonMergePatch = 1 << 4, | |||
// Input will also be set when MultipartFormData is set. | |||
MultipartFormData = 1 << 5, | |||
// Used in spread. | |||
Spread = 1 << 6, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not relevant to this pr, just want to clarify UsageFlags, if a model is used in
- patch operation for input
- another operation for spread input
- another operation for output
How many medels we will get from TCGC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two. one original model with path|output, one anonymous model with spread.
for (const sdkType of context.modelsMap?.values() ?? []) { | ||
// if a type only has spread usage, then it could be internal | ||
if (sdkType.usage === UsageFlags.Spread) { | ||
sdkType.access = "internal"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a model is only used for spread, does that mean the TCGC would not return that model in getAllModels by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will return it but with access internal
resolve: #772
several cases related with spread:
tcgc will do http body spread for 1 and 2, not for 3 and 4. and for http body model, 1, 2 will have a model
TestRequest
with spread usage and internal access.Adoption guideline for emitters:
For emitters that have already adopted
getAllOperations
, if an operation has spread parameters:SdkServiceMethod
are spread.SdkServiceOperation
is an anonymous model withUsage.Spread
usage andAccess.Internal
access. And thecorrespondingMethodParams
of the body will be list of the parameters ofSdkServiceMethod
.For emitters that have not adopted
getAllOperations
, emitters need to do:getHttpOperationWithCache
to prevent different body type resolving for spread cases.typespec-azure/packages/typespec-client-generator-core/src/types.ts
Lines 1311 to 1325 in 5d77ba3
getClientType
from the body type of operation with spread, the return model will be an anonymous model withUsage.Spread
usage andAccess.Internal
access. DO NOT CALLgetEffectivePayloadType
for body type if it is from spread.